<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<% String chipTracContext = "/" + ConfigManager.getChipTracContext(); %>
<%
    String closeWindowAfterSave     = ( String ) request.getAttribute( "closeWindowAfterSave" );
    String parentWindowActionType   = ( String ) request.getAttribute( "parentWindowActionType" );
    String popupWindowSessionExp    = ( String ) request.getAttribute( "popupWindowSessionExp" );
%>

<logic:present name="showPOPUP" >
<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/assembly_release.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/quickSearch.js"></script>

<SCRIPT language="JavaScript">
<% if ( closeWindowAfterSave != null && closeWindowAfterSave.equalsIgnoreCase( "true" ) ) { %>
    //window.opener.document.testReleaseForm.refreshedByPopUpScreen.value = "true";
    window.opener.document.testReleaseForm.refreshedByUser.value = "true";
    window.opener.document.testReleaseForm.action = '<%=chipTracContext%>/testRelease.do?action=<%=parentWindowActionType%>';
    window.opener.document.testReleaseForm.submit();
    window.close();
<% } %>
    function submitSelectedLots()
    {
        var form                    = document.testReleaseForm;
        var selectedLotsObj         = form.hiddenLot;
        var atleastOneLotSelected   = false;
        var errors                  = "";

        if( typeof( selectedLotsObj.length ) == "undefined" )
        {
            if( form['availableFabLotsList[0].selected'].checked == true )
            {
                atleastOneLotSelected = true;
            }
        }
        else
        {
            for( var i=0; i < selectedLotsObj.length; i++ )
            {
                if( form['availableFabLotsList[' + i + '].selected'].checked == true )
                {
                    atleastOneLotSelected = true;
                    break;
                }
            }
        }
        if( atleastOneLotSelected == false )
        {
            errors = "<li>Please select aleast on Lot Number";
        }
        if( errors != "" )
        {
            var pa=document.getElementById("errors");
            pa.innerHTML = errors;
            return;
        }
        else
        {
            document.testReleaseForm.action = '<%=chipTracContext%>/testRelease.do?action=searchNew&screenMode=popup&closeWindowAfterSave=true';
            document.testReleaseForm.submit();
        }
    }
    function showLotHistory( lotNumber )
    {
        newWindow = window.open( '<%=chipTracContext%>/lotHistory.do?lotNumber=' + lotNumber,'fabLotHistory','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=650,height=300,left=100,top=50,resizable=yes' );
        newWindow.moveTo( 100, 50 );
        newWindow.focus();
    }
    /*function getLotReleaseDetails( lotId )
    {
        newWindow = window.open('<%=chipTracContext%>/testRelease.do?action=showReleaseInfo&lotId=' + lotId ,'LotReleaseHistory','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=650,height=300,left=100,top=50,resizable=yes');
        newWindow.moveTo( 100, 50 );
        newWindow.focus();
    }*/
</SCRIPT>
</HEAD>
<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">
    <% if ( popupWindowSessionExp == null ) { %>
    <TABLE width="90%" align="center" cellpadding="2" cellspacing="2" border="0">
    <html:form action="/testRelease.do" method="POST" type="com.scalar.chiptrack.operations.release.forms.testReleaseForm" >
        <logic:present name="parentWindowActionType">
            <input type="hidden" name="parentWindowActionType" value='<%=request.getAttribute("parentWindowActionType")%>' >
        </logic:present>
    <logic:present name="testReleaseForm" property="availableFabLotsList">
    <bean:size id="lotsListSize" name="testReleaseForm" property="availableFabLotsList"/>
    <logic:greaterThan value="0" name="lotsListSize">
    <TR>
        <TD colspan='4'>
            <table width="100%" align="left" cellpadding="2" cellspacing="2" border="0">
                <tr>
                    <td width="100%" colspan="9" class="NArialW" align="center">Available Fab Lots</td>
                </tr>
                <tr>
                    <td width="100%" colspan="9" class="NArialL" align="left">&nbsp;<FONT id="errors" color='FF0000'></font></td>
                </tr>
                <tr>
                    <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Select</font>
                    </td>
                    <td width="15%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Lot Number</font>
                    </td>
                    <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Qty Avail</font>
                    </td>
                    <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Date In</font>
                    </td>
                    <%--
                      <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Exp Date Out</font>
                    </td>--%>
                    <td width="15%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Process</font>
                    </td>
                    <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Part Number</font>
                    </td>
                    <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Base Product</font>
                    </td>
                    <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Vendor</font>
                    </td>
                    <%--<td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <table border="0" cellpadding="2" cellspacing="0">
                            <tr><td colspan="3" class="NArialS" align="center"><font color="#FFFFFF"><b>---- HOLDS ----</b></font></td></tr>
                            <tr>
                                <td class="NArialS" align="center"><font color="#FFFFFF"><b>HOLD</b></font></td>
                                <td class="NArialS" align="center"><font color="#FFFFFF"><b>ENG</b></font></td>
                                <td class="NArialS" align="center"><font color="#FFFFFF"><b>RMA</b></font></td>
                            </tr>
                        </table>
                    </td>--%>
                </tr>
                <nested:iterate indexId="iteratorIdx" id="releaseLotObj" property="availableFabLotsList" type="com.scalar.chiptrack.operations.release.ReleaseLot">
                    <tr bgcolor='<%=iteratorIdx % 2 == 0 ? "#FFFFEE" : "#DEE1E2"%>'>
                        <td class="NArialL" align="center">
                            &nbsp;<nested:checkbox property="selected" />
                        </td>
                        <td class="NArialL" align="center">
                            <nested:write property="lotNumber" />
                        </td>
                        <td class="NArialL" align="center">
                            <nested:write property="qtyAvailable" />
                            <nested:hidden property="releaseLotAutoId" value="-1"/> <!--HARD CODING HARD CODING HARD CODING HARD CODING-->
                            <input type="hidden" name="hiddenLot">
                        </td>
                        <td class="NArialL" align="center">
                            <nested:write property="lotDateIn" />
                        </td>
                        <%--<td class="NArialL" align="center">
                            <nested:write property="lotExpectedDateOut" />
                        </td>--%>
                        <td class="NArialL" align="center">
                            <nested:write property="processType" />
                        </td>
                        <td class="NArialL" align="center">
                            &nbsp;<nested:write property="fromPartNumber" />
                        </td>
                        <td class="NArialL" align="center">
                            &nbsp;<nested:write property="baseProductName" />
                        </td>
                        <td class="NArialL" align="center">
                            <nested:write property="fromVendorName" />
                        </td>
                        <%--<td align="center" class="NArialL">
                            <table border="0" cellpadding="4" cellspacing="0">
                                <tr>
                                    <td class="NArialL" align="center"><b><nested:equal property="hold" value="true">&nbsp;X&nbsp;</nested:equal><nested:equal property="hold" value="false">&nbsp;&nbsp;&nbsp;</nested:equal></b></td>
                                    <td class="NArialL" align="center"><b><nested:equal property="eng" value="true">&nbsp;X&nbsp;</nested:equal><nested:equal property="eng" value="false">&nbsp;&nbsp;&nbsp;</nested:equal></b></td>
                                    <td class="NArialL" align="center"><b><nested:equal property="rma" value="true">&nbsp;X&nbsp;</nested:equal><nested:equal property="rma" value="false">&nbsp;&nbsp;&nbsp;</nested:equal></b></td>
                                </tr>
                            </table>
                        </td>--%>
                    </tr>
                </nested:iterate>
                <tr>
                    <td colspan="9" align="center">
                        <a href="javascript:submitSelectedLots();" onmouseover="window.status='Click to Insert new lots';return true" onmouseout="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" title="Click to Insert new lots"/></a>&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="javascript:window.close();" onmouseover="window.status='Click to Close this window';return true" onmouseout="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" title="Click to Close this window"/></a>
                    </td>
                </tr>
            </table>
        </TD>
    </TR>
    </logic:greaterThan>
    <logic:equal value="0" name="lotsListSize">
    <TR>
        <TD colspan='4' width="100%">
            <table width="100%" align="left" cellpadding="2" cellspacing="2" border="0">
                <tr>
                    <td width="100%" colspan="7" class="NArialW" align="center">No Lots are present to pull</td>
                </tr>
                <tr><td width="100%" colspan="7">&nbsp;</td></tr>
                <tr><td width="100%" colspan="7">&nbsp;</td></tr>
                <tr>
                    <td width="100%" colspan="7" class="NArialL" align="center"><a href="javascript:window.close();">Close</a></td>
                </tr>
            </table>
        </TD>
    </TR>
    </logic:equal>
    </logic:present>
    </html:form>
    </TABLE>
    <% } else { %>
    <table cellpadding='0' cellspacing='0' bgcolor='FDF5E6' border="0" width="100%"  height="100%" align=center>
        <tr>
            <td>
                <table align="center" border="0" width="40%" bgcolor="#FDF5E6">
                    <tr><td>&nbsp;</td></tr>
                    <tr><td align="center" ><font class="NArialL" ><font color="red">Session has been time out , Please close this window and login again.</font></font></td></tr>
                    <tr><td>&nbsp;</td></tr>
                    <tr><td align="center" ><a href="javascript:window.close();"><font class='NArialL'>[Close this window]</font></a></td></tr>
                </table>
            </td>
       </tr>
       <tr><td>&nbsp;</td></tr>
    </table>
    <% } %>
</BODY>
</HTML>
</logic:present>

<logic:notPresent name="showPOPUP">
    <nested:root  name="testReleaseForm">
    <logic:present name="testReleaseForm" property="availableLotsList">
    <bean:size id="lotsListSize" name="testReleaseForm" property="availableLotsList"/>
    <logic:greaterThan value="0" name="lotsListSize">
    <TR>
        <TD colspan='4' id="fabLotsForNewReleasesTable">
            <table width="100%" align="left" cellpadding="2" cellspacing="2" border="0">
                <tr>
                    <td width="90%" colspan="6" class="NArialL" align="left">
                        <input type="hidden" name="removeUnnecessaryLots" />
                        <a href="javascript:createNewTestRelease()" class="leftsection" onMouseOver="window.status='Click to generate Test Release';return true" onMouseout="window.status='';return ">Click here to Generate Test Release</a>
                    </td>
                    <td width="10%" class="NArialL" colspan="3" align="right">
                        <%--<a href="javascript:disableSelectedLots()" class="clickhere" onMouseOver="window.status='Click here to remove lot from search list';return true" onMouseOut="window.status='';return true">Click here to remove lots</a>--%>
                    </td>
                </tr>
                <tr><td colspan="9"><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='5'></td></tr>
                <tr>
                    <td width="5%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Select</font>
                    </td>
                    <td width="15%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Lot Number</font>
                    </td>
                    <td width="15%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Fab Lot Number</font>
                    </td>
                    <td width="8%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Qty Avail</font>
                    </td>
                    <td width="7%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Qty Issued</font>
                    </td>
                    <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Date In</font>
                    </td>
                    <%--<td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Exp Date Out</font>
                    </td>--%>
                    <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Process</font>
                    </td>
                    <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Part Number</font>
                    </td>
                    <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Base Product</font>
                    </td>
                    <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <font color="#FFFFFF">Vendor</font>
                    </td>
                    <%--<td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                        <table border="0" cellpadding="2" cellspacing="0">
                            <tr><td colspan="3" class="NArialS" align="center"><font color="#FFFFFF"><b>---- HOLDS ----</b></font></td></tr>
                            <tr>
                                <td class="NArialS" align="center"><font color="#FFFFFF"><b>HOLD</b></font></td>
                                <td class="NArialS" align="center"><font color="#FFFFFF"><b>ENG</b></font></td>
                                <td class="NArialS" align="center"><font color="#FFFFFF"><b>RMA</b></font></td>
                            </tr>
                        </table>
                    </td>--%>
                </tr>
                <nested:iterate indexId="iteratorIdx" id="releaseLotObj" property="availableLotsList" type="com.scalar.chiptrack.operations.release.ReleaseLot">
                    <tr bgcolor='<%=iteratorIdx % 2 == 0 ? "#FFFFEE" : "#DEE1E2"%>'>
                        <td class="NArialL" align="center">
                            &nbsp;<nested:checkbox property="selected" />
                        </td>

                        <td class="NArialL" align="center">
                            <nested:hidden property="lotId"/>
                           <A href="javascript:getLotReleaseDetails('<nested:write property="lotId"/>' )" class="leftsection"><nested:write property="lotNumber"/></A>
                       </td>

                        <td class="NArialL" align="center">
                            <nested:write property="fabLotNumber"/>
                        </td>

                        <td class="NArialL" align="center">
                            <nested:write property="qtyAvailable" />
                            <input type="hidden" name="hiddenLot">
                        </td>
                        <td class="NArialL" align="center">
                            <nested:write property="qtyOut" />

                        </td>
                        <td class="NArialL" align="center">
                            <nested:write property="lotDateIn" />
                        </td>
                        <%--<td class="NArialL" align="center">
                            <nested:write property="lotExpectedDateOut" />
                        </td>--%>
                        <td class="NArialL" align="center">
                            <nested:write property="processType" />
                        </td>
                        <td class="NArialL" align="center">
                            &nbsp;<nested:write property="fromPartNumber" />
                        </td>
                        <td class="NArialL" align="center">
                            &nbsp;<nested:write property="baseProductName" />
                        </td>
                        <td class="NArialL" align="center">
                            <nested:write property="fromVendorName"/>
                        </td>
                        <%--<td align="center" class="NArialL">
                            <table border="0" cellpadding="4" cellspacing="0">
                                <tr>
                                    <td class="NArialL" align="center"><b><nested:equal property="hold" value="true">&nbsp;X&nbsp;</nested:equal><nested:equal property="hold" value="false">&nbsp;&nbsp;&nbsp;</nested:equal></b></td>
                                    <td class="NArialL" align="center"><b><nested:equal property="eng" value="true">&nbsp;X&nbsp;</nested:equal><nested:equal property="eng" value="false">&nbsp;&nbsp;&nbsp;</nested:equal></b></td>
                                    <td class="NArialL" align="center"><b><nested:equal property="rma" value="true">&nbsp;X&nbsp;</nested:equal><nested:equal property="rma" value="false">&nbsp;&nbsp;&nbsp;</nested:equal></b></td>
                                </tr>
                            </table>
                        </td>--%>
                    </tr>
                </nested:iterate>
            </table>
        </TD>
    </TR>
    </logic:greaterThan>
    </logic:present>
    </nested:root>
</logic:notPresent>

<%--
<%}catch( Exception e ) { e.printStackTrace(); }  %>--%>
